/* ========================================================================= */
/* ------------------------------------------------------------------------- */
/*!
  \file			session.cc
  \date			Feb 2012
  \author		TNick

  \brief		Contains the implementation of Session class


*//*


 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Please read COPYING and README files in root folder
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
//
//
//
//
/*  INCLUDES    ------------------------------------------------------------ */

#include	<stdlib.h>

#include	<objdeflib.h>
#include	<objdeflib_internal.h>
#include	<objdef.h>


#include	"session.h"



/*  INCLUDES    ============================================================ */
//
//
//
//
/*  DEFINITIONS    --------------------------------------------------------- */

using namespace	ObjD;

/*  DEFINITIONS    ========================================================= */
//
//
//
//
/*  DATA    ---------------------------------------------------------------- */

ObjD::Session *		ObjD::def_ss = NULL;

/*  DATA    ================================================================ */
//
//
//
//
/*  CLASS    --------------------------------------------------------------- */

/* ------------------------------------------------------------------------- */
Session::Session	( void )
{
	p_predef = NULL;
	p_tree = NULL;
}
/* ========================================================================= */

/* ------------------------------------------------------------------------- */
Session::~Session	( void )
{
	unsigned		i;


	/* the tree of objects */
	ObjDef * kiter = static_cast<ObjDef *>( p_tree );
	while ( kiter != NULL )
	{
		kiter->discard();
		kiter = static_cast<ObjDef *>( kiter->next() );
	}


	/* the list of predefined objects */
	kiter = static_cast<ObjDef *>( p_predef );
	while ( kiter != NULL )
	{
		kiter->discard();
		kiter = static_cast<ObjDef *>( kiter->next() );
	}


	/* the list of names */
	for ( i = 0; i < names_.count(); i++ )
	{
		free( names_.at( i ) );
	}
	names_.clear();


	/* the ist of descriptions */
	for ( i = 0; i < descr_.count(); i++ )
	{
		free( descr_.at( i ) );
	}
	descr_.clear();


}
/* ========================================================================= */

#ifdef	OBJECTSLIB_TESTS

/* ------------------------------------------------------------------------- */
void				ObjD::Session_Tests					(
		int & performed, int & succeded )
{
	QString		Outcm;
	performed = 0;
	succeded = 0;
	bool		b_ok;

	TEST_RESULT( def_ss != NULL, "Default session was created" );

	for (;;)	{
		if( def_ss->p_predef != NULL ) break;
		if( def_ss->p_tree != NULL ) break;
		if( def_ss->names_.count() != 0 ) break;
		if( def_ss->descr_.count() != 0 ) break;

		if( def_ss->firstTemplate() != NULL ) break;
		if( def_ss->firstObject() != NULL ) break;

		if( def_ss->name( 0 ) != NULL ) break;
		if( def_ss->name( 10 ) != NULL ) break;
		if( def_ss->name( 100 ) != NULL ) break;
		if( def_ss->name( -1 ) != NULL ) break;

		if( def_ss->nameCount() != 0 ) break;
		if( def_ss->descrCount() != 0 ) break;


		b_ok = true;
		break;
	}
	TEST_RESULT( b_ok, "Default session initial state" );



}
/* ========================================================================= */

#endif

/*  CLASS    =============================================================== */
//
//
//
//
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
